<?php
namespace app\admin\controller;
// use app\index\
use think\captcha\Captcha;
class Login
{
    public function index()
    {
    	// print_r(112312313);exit;
		return view('index');
    }
    public function dologin()
    {
        $code=$_POST['vercode'];
        $username=$_POST['username'];
        $password=$_POST['password'];
        $checkCerify=$this->checkCerify($code);
        if(!$checkCerify){
            $mess['code']=100;
            $mess['msg']='验证码不正确';
            return json_encode($mess);
        }
        $where['username']=$username;
        $where['password']=md5($password);
        $data=db("admin")->where($where)->find();
        if(!$data){
            $mess['code']=100;
            $mess['msg']='用户名或密码错误';
            return json_encode($mess);
        }
        session("userMsg",$data);
    	$mess['code']=200;
    	$mess['msg']='登陆成功，欢迎回来！';
		return json_encode($mess);
    }
    public function checkCerify($value)
    {
        $captcha = new Captcha();
        return $captcha->check($value);
        // return $captcha->entry();    
    }
    public function outlogin()
    {
        session("userMsg",0);
        $mess['code']=200;
        $mess['msg']='退出登陆成功';
        return json_encode($mess);  
    }
    public function showVerify()
    {
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    30,    
            // 验证码位数
            // 'length'      =>    3,   
            // 关闭验证码杂点
            'useNoise'    =>    false, 
            // 'bg'          =>    false
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();    
    }
}
